#pragma once

#include "fxcc/core/platform/common/pch.h"

namespace fxcc
{
	namespace platform
	{
		namespace common
		{
			struct FXCC_API Mouse
			{
				struct FXCC_API _Ev
				{
					MouseButton m_Btn;
					ActionType m_Type;
				};
				Mouse()
					:m_LastCursorPos({ -1,-1 })
				{
					memset(m_States, 0, sizeof(m_States));
				}

				bool m_States[(int)MouseButton::COUNT];

				std::vector<_Ev> m_Evs;

				glm::ivec2 m_CursorPos;
				
				glm::ivec2 m_LastCursorPos;
				
				glm::ivec2 m_DeltaPos;

				glm::ivec2 m_Scroll;

				void SetCursorPos(const glm::ivec2 pos) {

					m_CursorPos = pos;
					if (m_LastCursorPos == glm::ivec2(-1, - 1))
					{
						m_DeltaPos = { 0,0 };
					}
					else
					{
						m_DeltaPos = m_CursorPos - m_LastCursorPos;
					}
					m_LastCursorPos = pos;
				}

				void SetScroll(const glm::ivec2 pos) { m_Scroll = pos; }

				void Callback(const MouseButton& btn, const ActionType& type)
				{
					m_States[(int)btn] = (bool)type;

					this->m_Evs.push_back({ btn, type });
				}

				void Clear()
				{
					m_DeltaPos = { 0 ,0};
					m_Evs.clear();
				}
				bool HasMouseDown(const MouseButton& btn) const
				{
					return HasEv(btn, ActionType::Down);
				}
				bool HasMouseUp(const MouseButton& btn)const
				{
					return HasEv(btn, ActionType::Up);
				}
				bool HasEv(const MouseButton& btn, const ActionType& type) const
				{
					for (const auto& it : m_Evs)
					{
						if (it.m_Btn == btn && it.m_Type == type)
						{
							return true;
						}
					}
					return false;
				}
				bool IsPressing(const MouseButton& btn) const
				{
					return m_States[(int)btn];
				}
			};
		};
	};
};